package com.woniuxy.demo.service.Impl;

import com.woniuxy.demo.entity.ResponseResult;
import com.woniuxy.demo.entity.User;
import com.woniuxy.demo.mapper.UserMapper;
import com.woniuxy.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 佘赛飞
 * @create 2021 -10 -12 7:25 PM
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User getUserByName(String username) {
        return userMapper.selectUserByName(username);
    }

    @Override
    public List<User> getUsers(User user, int pageIndex, int pageSize) {
        return userMapper.selectUsers(user,pageIndex,pageSize);
    }

    @Override
    public int getUserCount(User user) {
        return userMapper.selectUserCount(user);
    }
    //更新
    @Override
    public ResponseResult updateUser(User user) {
        try {
            userMapper.updateUser(user);
            return new ResponseResult(null,200,"修改成功");
        }catch (Exception e){
            return new ResponseResult(null,500,"修改失败");
        }
    }
    //新增
    @Override
    public ResponseResult addUser(User user) {
        try {
            userMapper.insertUser(user);
            return new ResponseResult(null,200,"添加成功");
        }catch (Exception e){
            return new ResponseResult(null,500,"添加失败");
        }
    }

    @Override
    public ResponseResult deleteUser(int uid) {
        try {
            userMapper.deleteUser(uid);
            return new ResponseResult(null, 200, "删除成功");
        } catch (Exception e) {
            return new ResponseResult(null, 500, "删除失败");
        }
    }

}
